package config

import (
	"fmt"
)

type Config struct {
	Mysql Mysql `json:"mysql"`
	Pg    Pg    `json:"pg"`
	Redis Redis `json:"redis"`
	Es    Es    `json:"es"`
	Dev   Dev   `json:"dev"`
}

type Es struct {
	Addresses []string `json:"addresses"`
	Username  string   `json:"username"`
	Password  string   `json:"password"`
}

type Dev struct {
	Mode string
}

type Mysql struct {
	Host     string
	Port     int
	User     string
	Password string
	Db       string
}

func (m *Mysql) GenerateDns() string {
	dns := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=true", m.User, m.Password, m.Host, m.Port, m.Db)

	fmt.Println(dns)
	return dns
}

type Pg struct {
	Host     string
	Port     int
	User     string
	Password string
	Db       string
}

func (p *Pg) GenerateDns() string {
	dns := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", p.Host, p.Port, p.User, p.Password, p.Db)
	fmt.Println(dns)
	return dns
}

type Redis struct {
	Host string
	Port int
}

var GlobalConfig = new(Config)
